Programming Basics
Outline
Digit are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
This is a base 10 numbering system, thus the word decimal
Place positions are one’s, ten’s, hundred’s, thousand’s, etc…
Place values are base on the powers of 10.
The powers of 10 are: 0, 10, 100, 1000, etc… this corresponds to 10^0, 10^1, 10^2, 10^3, etc…
The powers 0, 1, 2, 3, etc… corresponds to the one’s, ten’s, hundred’s, thousand’s, etc… place positions.
Programming Basics: Data Representation
What’s all this business about ones and zeros?
Binary Computers only know two things: One and Zero.
Structure is applied to groups on 1’s and 0’s to gain meaning.
If you start with 1 penny and double it each day, how much money do you have in 30 days?
If you start with 1 penny and double it each day with a 28% tax rate, how much money do you have in 30 days? ~$40K
Fishing with a bit might get you a nibble or even a byte.
As you tell the story the word gets longer and longer.
The world of black and white, true or false
10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 BLAST OFF!
How numbers are stored in a computer
Two’s company
1’s and 0’s using the power of 2 and grouped in different sizes
Even bits strive for significance
Right to Left, Least to Most
Bits are not egalitarian
Bit Position and relation to the power of two
What gives value to a binary number?
There is a lot of range in the digits 1 and 0
Using two digits in three places to get 8 values from 0 to 7
More Binary Number Calculations
What gives value to a binary number? Revisited
A more in-depth binary number calculation
An eight legged animal
Digits are 0 to 7; base 8
Use % as the notation
Finally something we can relate to, what a blessing
Digits are 0 to 9; base 10
You might think this is a curse
Digits are 0 to 9, A to F; base 16
Use $ as the notation
How to change a curse into a blessing
Tables of values
Division remainder method
Learning how to add all over again
Add 1’s and 0’s with carry
Signed Binary "Sign, sign, everywhere a sign"
How to represent negative numbers in binary
There is a problem though
Aren’t they so polite
A solution to negative number math, inverse the digits and add 1
"What you do that for" – Opie Taylor
A method to code signed floating point decimal numbers in binary only using the decimal digits 0 to 9
Who will rescue this point?
IEEE 754 standard
Programming builds character
ASCII, EBCDIC, Unicode
Programming Basics: Constructs
Let’s build something
In some traditions, the father of the modern digital computer
Here’s what you do for me
Symbolic representation of a memory location
Holds a value that can be changed
Schizophrenia
Restricted meanings can be placed on variables so that they have a smaller range of values. This aids in writing better programs.
Let’s be logical about this
Value range is restricted to True or False
It’s all in the numbers
Value range is restricted to integer or floating point values
Easy as 1,2, 3
Whole numbers, no decimal point
Take a bite
8 bit range
How’s the view down there?
16 bit range
A.K.A. Integer
16 or 32 bit range
Kinda like this lecture
32 or 64 bit range
Still no rescue
Numbers with a decimal point
Different sizes used to conserve memory usage
Trouble
A good range of values
Double trouble
A large range of values
Will the insanity ever end?
An enormous range of values
There are lots of characters
Single characters or a string of characters
Here is one character
Encoded with some character coding scheme like ASCII
Here are a bunch of characters
Very convenient but lots of overhead
A table of values
A complex variable with several components
The variable name of the array
The variable type of the values in the array
Values in the different array slots
Places in the array where individual values are stored
The extra referencing item besides the variable name to access the different locations where values are stored in the array
An array with more than one index to reference the different locations in the array
Never changes
Proper use is good programming practice
Programming is very expressive
The left hand learns what the right hand is doing
Add, Subtract, Multiply, Divide, Modulus, Power
And, Or, Not, Xor truth tables
Equal, Not Equal, Less Than, Greater Than and combinations of such
Order of expression evaluation and the use of Parentheses ( )
Binary And, Or, Not, Xor, Left Shift, Right Shift
Making Decisions
If (true) Then…
Else (it must be false) …
Short hand way of doing nested If..Then.Else statements
Take a fork in the road
Unconditional branching
Considered poor programming practice because it violates the one entry point and one exit point of a module as described in structured programming
This looping form is to be used when the number of times that the loop should be performed can be pre-determined
This looping form is to be used when a test should be done before the loop should be executed, even the first time. The loop may execute zero (0) to N times, where N may or may not pre-determined
This looping form is to be used when a test should be done after the loop has executed at least one time. The loop will execute one (1) to N times, where N may or may not pre-determined
Communicating with the world outside of the program
Method for organizing code, facilitating code reuse
Do something but do NOT return a value
Do something and DO return a value
Information into the subroutine
Call by value
Call by reference
Function return value, explicitly or implicitly assigned